<template>
  <div>
    <Search :search="search" :reset="reset">
      <template v-slot:body>
        <el-form-item label="工序代号" prop="workingcode">
          <el-input v-model="query.workingcode" name="workingcode" clearable />
        </el-form-item>

        <el-form-item label="工序名称" prop="processname">
          <el-input v-model="query.processname" name="processname" clearable />
        </el-form-item>

        <el-form-item label="描述" prop="description">
          <el-input v-model="query.description" name="description" clearable />
        </el-form-item>
      </template>
    </Search>
    <div class="table-default">
      <Operate :show="open" v-if="!props.ischose" />
      <el-table :data="tableData" class="mt-3" v-loading="loading" border>
        <el-table-column prop="id" label="行号" />
        <el-table-column prop="workingcode" label="工序代号" min-width="120" />
        <el-table-column prop="processname" label="工序名称" min-width="120" />
        <el-table-column prop="description" label="描述" min-width="120" />
        <el-table-column prop="processtype" label="工序类型" min-width="120" />
        <el-table-column prop="toallow" label="是否允许合并" min-width="120" />
        <el-table-column prop="creator_id" label="创建者" min-width="120" />
        <el-table-column prop="created_at" label="创建时间" min-width="150" />
        <el-table-column prop="modifier" label="修改者" min-width="120" />
        <el-table-column prop="updated_at" label="修改时间" min-width="150" />
        <el-table-column label="操作" width="200" fixed="right">
          <template #default="scope">
            <el-button type="warning" @click="choseHandler(scope.row)" size="small" v-if="props.ischose">选择</el-button>
            <Update @click="open(scope.row.id)" v-if="!props.ischose" />
            <Destroy @click="destroy(api, scope.row.id)" v-if="!props.ischose" />
          </template>
        </el-table-column>
      </el-table>
      <Paginate />
    </div>

    <Dialog v-model="visible" :title="title" destroy-on-close>
      <Create @close="close(reset)" :primary="id" :api="api" />
    </Dialog>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'processdata',
})
</script>


<script lang="ts" setup>
import { computed, onMounted } from 'vue'
import Create from './create.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'

const api = 'promanagement/processdata'

const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

let emit = defineEmits('send-Obj')

const choseHandler = row => {
  console.log(row)
  let sendObj = {
    processdata_id: row.id,
    processname: row.processname,
  }
  emit('send-Obj', sendObj)

}

const props = defineProps({
  ischose: Boolean,
})

onMounted(() => {
  search()
  deleted(reset)
})
</script>
